<template>
  <view class="marketing-card" @click="jumpToBuyPage">
    <view class="left-image"></view>
    <view class="right-info">
      <span class="title">职途顾问服务</span>
      <span class="desc">1V1精细化服务，助力人才求职</span>
      <view class="price-info">
        <span class="current-price">￥49.9</span>
        <view class="original-price"
          >￥299
          <view class="red-line"></view>
        </view>
        <view class="falsh-sales">限时特惠</view>
      </view>
    </view>
    <view class="buy-button" v-if="!isConsultant">去购买</view>
  </view>
</template>

<script>
import { getVasRights } from "@/api/modules/career";
export default {
  name: "marketingCard",
  props: {
    isConsultant: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isBuy: 0,
    };
  },
  created() {
    this.getVasRights();
  },
  methods: {
    async getVasRights() {
      const params = {
        cardType: uni.getStorageSync("cardType"),
        personId: uni.getStorageSync("person-id").slice(2) || "",
      };
      const res = await getVasRights(params);
      if (res.code == 200) {
        if (res.data.CONSULTE_SERVICE) {
          this.isBuy = res.data.CONSULTE_SERVICE.isBuy;
          // if (this.isBuy) {
          //   uni.showToast({
          //     title: "当前服务已购买，无需重复购买~",
          //     icon: "none",
          //   });
          // } else {
          //   uni.navigateTo({
          //     url: `/pagesSub/userCenter/careerPathV2/components/BuyPage`,
          //   });
          // }
        }
      }
    },
    jumpToBuyPage() {
      this.getVasRights();
      console.log("跳转到购买页面");
      if (this.isConsultant) {
        console.log("这里是顾问视角，不做任何跳转");
      } else {
        // this.getVasRights();
        if (this.isBuy) {
          uni.showToast({
            title: "当前服务已购买，无需重复购买~",
            icon: "none",
          });
        } else {
          uni.navigateTo({
            url: `/pagesSub/userCenter/careerPathV2/components/BuyPage`,
          });
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
$img-base-message: $img-base + "careerPath/";

.marketing-card {
  height: 184rpx;
  /* margin: 0 32rpx; */
  background-color: #ffffff;
  padding: 24rpx 20rpx 20rpx 20rpx;
  border-radius: 8rpx;
  display: flex;
  flex-direction: row;
  position: relative;
  .left-image {
    width: 140rpx;
    height: 140rpx;
    border-radius: 5rpx;
    background-image: url($img-base-message + "salePic.png");
    background-size: 100% 100%;
  }
  .right-info {
    margin-left: 12rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .title {
      font-size: 32rpx;
      font-family: PingFang-SC, PingFang-SC;
      font-weight: bold;
      color: #000000;
    }
    .desc {
      font-size: 26rpx;
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      color: #bfbfbf;
    }
    .price-info {
      display: flex;
      flex-direction: row;
      align-items: center;
      .current-price {
        font-size: 32rpx;
        font-family: PingFang-SC, PingFang-SC;
        font-weight: 800;
        color: #f75a3e;
      }
      .original-price {
        margin-left: 18rpx;
        font-size: 24rpx;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        color: #555550;
        position: relative;
        .red-line {
          width: 100%;
          height: 2rpx;
          background-color: #f75a3e;
          position: absolute;
          top: 45%;
        }
      }
      .falsh-sales {
        width: 104rpx;
        height: 40rpx;
        background: #fff2f0;
        border-radius: 4rpx;
        border: 2rpx solid #f75a3e;
        font-size: 20rpx;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        color: #ff411f;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        margin-left: 16rpx;
      }
    }
  }
  .buy-button {
    position: absolute;
    bottom: 20rpx;
    right: 20rpx;
    width: 112rpx;
    height: 48rpx;
    background: #f75a3e;
    border-radius: 33rpx;
    font-size: 20rpx;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }
}
</style>
